package com.wgq.IO;

import java.io.*;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class JDBCResoureToFile {
    public HashMap JDBCResoureToShow(){
        HashMap map =null;
        try {
            //加载驱动
          Class cla = Class.forName("com.wgq.JDBC.JdbcDome");
                //反射私有方法
                Method method= cla.getDeclaredMethod("getJDBCResoure");
                method.setAccessible(true);
                    //创建反射类的构造方法  创建实例
                    Object obj = cla.newInstance();
                        //调用该对象对应的反射方法 即: getJDBCResoure
                         map =  (HashMap) method.invoke(obj);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

    return map;
    }

    public void JDBCResoureToFile() throws IOException {
    String fileName="JDBCResoure.txt";
    File file = new File(fileName);
    file.createNewFile();
    FileWriter writer = new FileWriter(fileName) ;
    HashMap<Integer,String> map  = JDBCResoureToShow();
    Iterator<Map.Entry<Integer,String>> it = map.entrySet().iterator();
    while (it.hasNext()){
        Map.Entry<Integer,String >  en = it.next();
        writer.write(en.getKey()+"\t"+en.getValue()+"\n");
    }
    writer.write("三十功名尘与土");
    writer.close();
    }

    public void copyToBufferForFile(){
       String resoure = "C:\\Users\\ACER\\Desktop\\1.jpg";
       String dest = "C:\\Users\\ACER\\Desktop\\2.jpg";
       File fileInput = new File(resoure);
       File fileOutput = new File(dest);
        try {
            FileInputStream fInput = new FileInputStream(fileInput);
            FileOutputStream fOutput = new FileOutputStream(fileOutput);
            byte arr[] = new byte[1024];
            while ((fInput.read(arr,0,arr.length))!=-1){
                fOutput.write(arr,0,arr.length);
            }
            fOutput.flush();
            fOutput.close();
            fInput.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) throws IOException {
          JDBCResoureToFile jb= new JDBCResoureToFile();
//        HashMap map =  jb.JDBCResoureToShow();
//        Iterator<HashMap.Entry<Object,String>> it = map.entrySet().iterator();
//        while (it.hasNext()){
//            HashMap.Entry<Object,String> entry = it.next();
//            System.out.println(entry.getKey()+"\t"+entry.getValue());
//        }
         jb.JDBCResoureToFile();
    }
}
